﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LevelManager : MonoBehaviour {

    Dictionary<int, int> a;
    private int levelNum = 7;

    // Use this for initialization
    void Start () {
        Init();
	}

    void Init()
    {
        /*
        Dictionary<int, int> data = Singleton.GetInstance().levelData;

        foreach (var item in data)
        {
            //获取当前关卡
            Transform curLevel = transform.GetChild(item.Key - 1);
            Debug.Log(curLevel.gameObject.name);
            //获取关卡解锁图片
            Transform curState = curLevel.GetChild(0);
            Debug.Log(curState.gameObject.name);

            switch (item.Value)
            {
                //未解锁
                case 0:
                    curState.gameObject.SetActive(true);
                    break;
                //解锁
                case 1:
                    curState.gameObject.SetActive(false);
                    break;
                default:
                    break;
            }
        }
        */

        for (int i = 1; i < levelNum+1; i++)
        {
            Transform nextLevel;
            Transform nextState;

            //获取当前关卡
            Transform curLevel = transform.GetChild(i-1);
            //下一关
            if (i < 7)//防止下一关不存在的情况
            {
                nextLevel = transform.GetChild(i);
                nextState = nextLevel.GetChild(0);
                Debug.Log(nextState.gameObject.name);
            }
            else
            {
                return;
            }

            //获取关卡解锁图片
            Transform curState = curLevel.GetChild(0);

            //默认为3（此处不能为0）
            int j = PlayerPrefs.GetInt(i.ToString(), 3);

            switch (j)
            {
                //未解锁
                case 0:
                    curState.gameObject.SetActive(true);
                    nextState.gameObject.SetActive(true);
                    break;
                //解锁
                case 1:
                    curState.gameObject.SetActive(false);
                    curLevel.gameObject.GetComponent<Button>().enabled = true;
                    nextState.gameObject.SetActive(false);
                    nextLevel.gameObject.GetComponent<Button>().enabled = true;
                    break;
                default:
                    break;
            }
        }
    }
}
